namespace two {

    export function onRefreshApi(api: string): void {
        refreshApi(api, sceneLayer);
        refreshApi(api, boxLayer);
    }

    function refreshApi(api: string, layer: egret.DisplayObjectContainer): void {
        for (let i = 0; i < layer.numChildren; i++) {
            let ui = layer.getChildAt(i) as BaseComponent;
            if (!ui.isClosed) {
                if (ui.numChildren) {
                    refreshApi(api, ui);
                }

                if (ui.refreshApi) {
                    ui.refreshApi(api);
                }
            }
        }
    }

    export function onRefreshData(type: string, data: any): void {
        refreshData(type, data, sceneLayer);
        refreshData(type, data, boxLayer);
    }

    function refreshData(type: string, data: any, layer: egret.DisplayObjectContainer): void {
        for (let i = 0; i < layer.numChildren; i++) {
            let ui = layer.getChildAt(i) as BaseComponent;
            if (!ui.isClosed) {
                if (ui.numChildren) {
                    refreshData(type, data, ui);
                }

                if (ui.refreshApi) {
                    ui.refreshData(type, data);
                }
            }
        }
    }
}